#include <cstdio>
#include <algorithm>

using namespace std;

int main(int argc, char const *argv[])
{
    int n, m, *arr;
    int i, j;
    scanf("%d%d", &n, &m);
    arr = new int[n];
    for (i = 0; i < n; i++)
    {
        scanf("%d", &arr[i]);
    }
    for (i = 0; i < m; i++)
    {
        next_permutation(arr, arr + n);
    }
    for (i = 0; i < n; i++)
    {
        printf("%d ", arr[i]);
    }
    
    return 0;
}
